import { notification, Modal } from 'antd';
import {browserHistory} from 'react-router';
import * as axios from 'axios';
axios.defaults.baseURL = window.GLOBAL.baseURL;
axios.defaults.headers.post['Content-Type'] = window.GLOBAL.contentType;

//查找反馈详情
export function feedbackDetail(obj, fbId) {
    if(sessionStorage.getItem("staffAuth") != null){
        axios.defaults.headers.common['staffAuth'] = sessionStorage.getItem('staffAuth');
    }

    axios.post('/webAPI/feedback/feedbackDetail/' + fbId, null)
    .then(function (response) {
        if(response.data.code == 1){
          if(response.data.data.feedback.replyContent == undefined){
            obj.setState({userProfile: response.data.data.userProfile, feedback: response.data.data.feedback, isDisable: false});
          }else {
            obj.setState({userProfile: response.data.data.userProfile, feedback: response.data.data.feedback, isDisable: true});
          }
        }
    }).catch(function(err){
        notification.error({
            placement: 'bottomRight',
            message: '提示：',
            description: '对不起，服务器连接错误，请联系相关管理人员。',
            style: {
              borderLeft: '4px solid rgb(240, 70, 52)'
            }
        });
    })
}
//回复反馈信息
export function replyFeedback(obj, paramData) {
    if(sessionStorage.getItem("staffAuth") != null){
        axios.defaults.headers.common['staffAuth'] = sessionStorage.getItem('staffAuth');
    }

    axios.post('/webAPI/feedback/replyFeedback', paramData)
    .then(function (response) {
        if(response.data.code == 1){
          obj.setState({ feedbackVisible: false, replyContent: "" });
          Modal.success({
            title: '提示：',
            content: '意见回复成功。',
            onOk: function () {
              feedbackDetail(obj, obj.props.routeParams.id);
            }
          });
        }
    }).catch(function(err){
        notification.error({
            placement: 'bottomRight',
            message: '提示：',
            description: '对不起，服务器连接错误，请联系相关管理人员。',
            style: {
              borderLeft: '4px solid rgb(240, 70, 52)'
            }
        });
    })
}
